﻿using System;
using System.Collections.Generic;
using System.Text;
using CMN.DAL;
using CMN.Entity;
using System.Data;
using System.Data.Common;
namespace CMN.BLL
{
    public class BLLHelper
    {

        #region 当前数据库类型
        /// <summary>
        /// 返回数据库类型字符串形式
        /// </summary>
        /// <returns></returns>
        public  string GetDBType()
        {
            return DALHelper.CMNHelper.DatabaseType.ToString();
        }

        public  DBUtility.DBHelper GetDalHelper()
        {
            return DALHelper.CMNHelper;
        }
        #endregion 

        #region 返回查询的字段值
        /// <summary>
        /// 返回查询的字段值
        /// </summary>
        /// <param name="sql">执行的语句</param>
        /// <returns>字符串类型</returns>
        public  string ExecuteScalar(string sql)
        {
            object obj = DALHelper.CMNHelper.ExecuteScalar(CommandType.Text, sql, null);
            if (obj == null)
            {
                return "";
            }
            else
            {
                return obj.ToString();
            }
        }
        #endregion

        #region 构造sql语句
        /// <summary>
        /// 获取分页SQL
        /// </summary>
        /// <param name="qp">查询条件类</param>
        /// <returns></returns>
        public  string GetPagerSQL(QueryParam qp)
        {
            return DALHelper.CMNHelper.GetPagerSQL(qp);
        }

        /// <summary>
        /// 时间转sql语句
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public  string GetSqlDateTime(DateTime dt)
        {
            return DALHelper.CMNHelper.GetSqlDateTime(dt);
        }
        #endregion

        #region 更新字段方法
        /// <summary>
        /// 更新数据库字段
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="TableFiledsValue">更新字段和值</param>
        /// <param name="Where">更新条件</param>
        /// <returns></returns>
        public  int Update(string table, string TableFiledsValue, string Where)
        {
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, string.Concat("update ", table, " set ", TableFiledsValue, " where ", Where), null);

        }

        #endregion

        #region "Sys_Field (系统应用字段 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_FieldEntity (系统应用字段)
        /// </summary>
        /// <param name="fam">Sys_FieldEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_FieldInsertUpdateDelete(Sys_FieldEntity fam)
        {
            return DALHelper.CMNHelper.Sys_FieldInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据FieldID返回 Sys_FieldEntity实体类 单笔资料 (系统应用字段)
        /// </summary>
        /// <param name="FieldID">FieldID 应用字段ID号</param>
        /// <returns>返回 Sys_FieldEntity实体类 FieldID为0则无记录</returns>
        public  Sys_FieldEntity Sys_FieldDisp(Int32 FieldID)
        {
            Sys_FieldEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_Field", "FieldID", FieldID);
            int RecordCount = 0;
            List<Sys_FieldEntity> lst = Sys_FieldList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_FieldEntity实体类的List对象 (系统应用字段)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_FieldEntity实体类的List对象(系统应用字段)</returns>
        public  List<Sys_FieldEntity> Sys_FieldList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_Field";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "FieldID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "FieldID";
            }
            return DALHelper.CMNHelper.Sys_FieldList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((系统应用字段))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_FieldDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_Field where FieldID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
        #region "Sys_FieldValue (应用字段值 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_FieldValueEntity (应用字段值)
        /// </summary>
        /// <param name="fam">Sys_FieldValueEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_FieldValueInsertUpdateDelete(Sys_FieldValueEntity fam)
        {
            return DALHelper.CMNHelper.Sys_FieldValueInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据ValueID返回 Sys_FieldValueEntity实体类 单笔资料 (应用字段值)
        /// </summary>
        /// <param name="ValueID">ValueID 索引ID号</param>
        /// <returns>返回 Sys_FieldValueEntity实体类 ValueID为0则无记录</returns>
        public  Sys_FieldValueEntity Sys_FieldValueDisp(Int32 ValueID)
        {
            Sys_FieldValueEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_FieldValue", "ValueID", ValueID);
            int RecordCount = 0;
            List<Sys_FieldValueEntity> lst = Sys_FieldValueList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_FieldValueEntity实体类的List对象 (应用字段值)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_FieldValueEntity实体类的List对象(应用字段值)</returns>
        public  List<Sys_FieldValueEntity> Sys_FieldValueList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_FieldValue";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "ValueID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "ValueID";
            }
            return DALHelper.CMNHelper.Sys_FieldValueList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((应用字段值))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_FieldValueDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_FieldValue where ValueID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
 

        #region "Sys_Event (系统日记表 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_EventEntity (系统日记表)
        /// </summary>
        /// <param name="fam">Sys_EventEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_EventInsertUpdateDelete(Sys_EventEntity fam)
        {
            return DALHelper.CMNHelper.Sys_EventInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据EventID返回 Sys_EventEntity实体类 单笔资料 (系统日记表)
        /// </summary>
        /// <param name="EventID">EventID 事件ID号</param>
        /// <returns>返回 Sys_EventEntity实体类 EventID为0则无记录</returns>
        public  Sys_EventEntity Sys_EventDisp(Int32 EventID)
        {
            Sys_EventEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_Event", "EventID", EventID);
            int RecordCount = 0;
            List<Sys_EventEntity> lst = Sys_EventList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_EventEntity实体类的List对象 (系统日记表)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_EventEntity实体类的List对象(系统日记表)</returns>
        public  List<Sys_EventEntity> Sys_EventList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_Event";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "EventID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "EventID";
            }
            return DALHelper.CMNHelper.Sys_EventList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((系统日记表))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_EventDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_Event where EventID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
 

        #region "Sys_Module (功能模块 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_ModuleEntity (功能模块)
        /// </summary>
        /// <param name="fam">Sys_ModuleEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_ModuleInsertUpdateDelete(Sys_ModuleEntity fam)
        {
            return DALHelper.CMNHelper.Sys_ModuleInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据ModuleID返回 Sys_ModuleEntity实体类 单笔资料 (功能模块)
        /// </summary>
        /// <param name="ModuleID">ModuleID 功能模块ID号</param>
        /// <returns>返回 Sys_ModuleEntity实体类 ModuleID为0则无记录</returns>
        public  Sys_ModuleEntity Sys_ModuleDisp(Int32 ModuleID)
        {
            Sys_ModuleEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_Module", "ModuleID", ModuleID);
            int RecordCount = 0;
            List<Sys_ModuleEntity> lst = Sys_ModuleList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_ModuleEntity实体类的List对象 (功能模块)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_ModuleEntity实体类的List对象(功能模块)</returns>
        public  List<Sys_ModuleEntity> Sys_ModuleList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_Module";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "ModuleID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "ModuleID";
            }
            return DALHelper.CMNHelper.Sys_ModuleList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((功能模块))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_ModuleDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_Module where ModuleID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
        #region "Sys_ModuleExtPermission (模块扩展权限 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_ModuleExtPermissionEntity (模块扩展权限)
        /// </summary>
        /// <param name="fam">Sys_ModuleExtPermissionEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_ModuleExtPermissionInsertUpdateDelete(Sys_ModuleExtPermissionEntity fam)
        {
            return DALHelper.CMNHelper.Sys_ModuleExtPermissionInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据ExtPermissionID返回 Sys_ModuleExtPermissionEntity实体类 单笔资料 (模块扩展权限)
        /// </summary>
        /// <param name="ExtPermissionID">ExtPermissionID 扩展权限ID</param>
        /// <returns>返回 Sys_ModuleExtPermissionEntity实体类 ExtPermissionID为0则无记录</returns>
        public  Sys_ModuleExtPermissionEntity Sys_ModuleExtPermissionDisp(Int32 ExtPermissionID)
        {
            Sys_ModuleExtPermissionEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_ModuleExtPermission", "ExtPermissionID", ExtPermissionID);
            int RecordCount = 0;
            List<Sys_ModuleExtPermissionEntity> lst = Sys_ModuleExtPermissionList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_ModuleExtPermissionEntity实体类的List对象 (模块扩展权限)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_ModuleExtPermissionEntity实体类的List对象(模块扩展权限)</returns>
        public  List<Sys_ModuleExtPermissionEntity> Sys_ModuleExtPermissionList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_ModuleExtPermission";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "ExtPermissionID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "ExtPermissionID";
            }
            return DALHelper.CMNHelper.Sys_ModuleExtPermissionList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((模块扩展权限))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_ModuleExtPermissionDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_ModuleExtPermission where ExtPermissionID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
 
        #region "Sys_RolePermission (角色应用权限表 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_RolePermissionEntity (角色应用权限表)
        /// </summary>
        /// <param name="fam">Sys_RolePermissionEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_RolePermissionInsertUpdateDelete(Sys_RolePermissionEntity fam)
        {
            return DALHelper.CMNHelper.Sys_RolePermissionInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据PermissionID返回 Sys_RolePermissionEntity实体类 单笔资料 (角色应用权限表)
        /// </summary>
        /// <param name="PermissionID">PermissionID 角色应用权限自动ID</param>
        /// <returns>返回 Sys_RolePermissionEntity实体类 PermissionID为0则无记录</returns>
        public  Sys_RolePermissionEntity Sys_RolePermissionDisp(Int32 PermissionID)
        {
            Sys_RolePermissionEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_RolePermission", "PermissionID", PermissionID);
            int RecordCount = 0;
            List<Sys_RolePermissionEntity> lst = Sys_RolePermissionList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 根据应用Id,角色ID,获得权限列表
        /// </summary>
        /// <param name="applicationid">应用id</param>
        /// <param name="roleid">角色ID</param>
        /// <returns>角色权限实体类</returns>
        public  Sys_RolePermissionEntity Sys_RolePermissionByCodeAndRoleId(string PageCode, int roleid)
        {
            QueryParam qp = new QueryParam();
            qp.Where = string.Format("  P_PageCode='{0}' and P_RoleID='{1}' ", PageCode, roleid);
            int rInt = 0;
            List<Sys_RolePermissionEntity> listRolePermission = Sys_RolePermissionList(qp, out rInt);
            if (listRolePermission.Count > 0)
            {
                return listRolePermission[0];
            }
            return null;
        }

        /// <summary>
        /// 返回Sys_RolePermissionEntity实体类的List对象 (角色应用权限表)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_RolePermissionEntity实体类的List对象(角色应用权限表)</returns>
        public  List<Sys_RolePermissionEntity> Sys_RolePermissionList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_RolePermission";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "PermissionID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "PermissionID";
            }
            return DALHelper.CMNHelper.Sys_RolePermissionList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((角色应用权限表))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_RolePermissionDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_RolePermission where PermissionID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }

        /// <summary>
        /// 批量删除((角色应用权限表))
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_RolePermissionDelByRoleId(int roleId)
        {
            string strDel = string.Concat("delete from  Sys_RolePermission where P_RoleID=", roleId.ToString());
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
        #region "Sys_Roles (角色表 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_RolesEntity (角色表)
        /// </summary>
        /// <param name="fam">Sys_RolesEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_RolesInsertUpdateDelete(Sys_RolesEntity fam)
        {
            return DALHelper.CMNHelper.Sys_RolesInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据RoleID返回 Sys_RolesEntity实体类 单笔资料 (角色表)
        /// </summary>
        /// <param name="RoleID">RoleID 角色ID自动ID</param>
        /// <returns>返回 Sys_RolesEntity实体类 RoleID为0则无记录</returns>
        public  Sys_RolesEntity Sys_RolesDisp(Int32 RoleID)
        {
            Sys_RolesEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_Roles", "RoleID", RoleID);
            int RecordCount = 0;
            List<Sys_RolesEntity> lst = Sys_RolesList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_RolesEntity实体类的List对象 (角色表)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_RolesEntity实体类的List对象(角色表)</returns>
        public  List<Sys_RolesEntity> Sys_RolesList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_Roles";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "RoleID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "RoleID";
            }
            return DALHelper.CMNHelper.Sys_RolesList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((角色表))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_RolesDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_Roles where RoleID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }



        #endregion

        #region "Sys_Online(在线用户表) - Method"


        /// <summary>
        /// 新增/删除/修改 Sys_OnlineEntity (在线用户表)
        /// </summary>
        /// <param name="fam">Sys_OnlineEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_OnlineInsertUpdateDelete(Sys_OnlineEntity fam)
        {
            return DALHelper.CMNHelper.Sys_OnlineInsertUpdateDelete(fam);
        }

        /// <summary>
        /// 根据OnlineID返回 Sys_OnlineEntity实体类 单笔资料 (在线用户表)
        /// </summary>
        /// <param name="OnlineID">OnlineID 自动ID</param>
        /// <returns>返回 Sys_OnlineEntity实体类 OnlineID为0则无记录</returns>
        public  Sys_OnlineEntity Sys_OnlineDisp(Int32 OnlineID)
        {
            Sys_OnlineEntity fam = new Sys_OnlineEntity();
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_Online", "OnlineID", OnlineID);
            int RecordCount = 0;
            List<Sys_OnlineEntity> lst = Sys_OnlineList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_OnlineEntity实体类的List对象 (在线用户表)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_OnlineEntity实体类的List对象(在线用户表)</returns>
        public  List<Sys_OnlineEntity> Sys_OnlineList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_Online";
            if (qp.Orderfld == null)
            {
                qp.Orderfld = "OnlineID";
            }


            if (qp.ReturnFields == null)
            {
                qp.ReturnFields = "*";
            }
            return DALHelper.CMNHelper.Sys_OnlineList(qp, true, out RecordCount);
        }
        #endregion

        #region "Sys_User (用户表 ) - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_UserEntity (用户表)
        /// </summary>
        /// <param name="fam">Sys_UserEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 Sys_UserInsertUpdateDelete(Sys_UserEntity fam)
        {
            return DALHelper.CMNHelper.Sys_UserInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据UserID返回 Sys_UserEntity实体类 单笔资料 (用户表)
        /// </summary>
        /// <param name="UserID">UserID 用户ID号</param>
        /// <returns>返回 Sys_UserEntity实体类 UserID为0则无记录</returns>
        public  Sys_UserEntity Sys_UserDisp(Int32 UserID)
        {
            Sys_UserEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Sys_User", "UserID", UserID);
            int RecordCount = 0;
            List<Sys_UserEntity> lst = Sys_UserList(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回Sys_UserEntity实体类的List对象 (用户表)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_UserEntity实体类的List对象(用户表)</returns>
        public  List<Sys_UserEntity> Sys_UserList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_User";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "UserID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "UserID";
            }
            return DALHelper.CMNHelper.Sys_UserList(qp, true, out RecordCount);
        }

        /// <summary>
        /// 批量删除((用户表))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_UserDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_User where UserID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
        #region "Sys_UserRoles - Method"
        /// <summary>
        /// 新增/删除/修改 Sys_UserRoles
        /// </summary>
        /// <param name="fam">Sys_UserRolesEntity实体类</param>
        /// <returns>返回0操正常</returns>
        public  int Sys_UserRolesInsertUpdateDelete(Sys_UserRolesEntity fam)
        {
            return DALHelper.CMNHelper.Sys_UserRolesInsertUpdateDelete(fam);
        }

        /// <summary>
        /// 返回Sys_UserRolesTable实体类的ArrayList对象
        /// </summary>
        /// <param name="qp">查询类</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>Sys_UserRolesTable实体类的ArrayList对象</returns>
        public  List<Sys_UserRolesEntity> Sys_UserRolesList(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Sys_UserRoles";
            
            qp.ReturnFields = "*";
            if (qp.Orderfld == null)
            {
                qp.Orderfld = "R_UserID,R_RoleID";
            }
            return DALHelper.CMNHelper.Sys_UserRolesList(qp, true, out RecordCount);
        }


        /// <summary>
        /// 根据ID返回 Sys_UserRolesTable实体类 单笔资料
        /// </summary>
        /// <param name="R_UserID"></param>
        /// <param name="R_RoleID"></param>
        /// <returns>返回Sys_UserRolesTable实体类 为0则无记录</returns>
        public  Sys_UserRolesEntity Sys_UserRolesDisp(int R_UserID, int R_RoleID)
        {
            Sys_UserRolesEntity fam = new Sys_UserRolesEntity();
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.ReturnFields = "*";
            qp.TableName = "Sys_UserRoles";
            qp.Where = "  Sys_UserRoles.R_UserID = " + R_UserID.ToString() + " and Sys_UserRoles.R_RoleID=" + R_RoleID.ToString();
            int RecordCount = 0;
            List<Sys_UserRolesEntity> lst = DALHelper.CMNHelper.Sys_UserRolesList(qp, true, out RecordCount);
            if (RecordCount > 0)
            {
                fam = (Sys_UserRolesEntity)lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 根据ID返回 Sys_UserRolesTable实体类 集合
        /// </summary>
        /// <param name="R_UserID"></param>
        /// <returns>返回Sys_UserRolesTable实体类 为0则无记录</returns>
        public  List<Sys_UserRolesEntity> Sys_UserRolesDisp(int R_UserID)
        {

            Sys_UserRolesEntity fam = new Sys_UserRolesEntity();
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
         
            qp.ReturnFields = "*";
            qp.TableName = "Sys_UserRoles";
            qp.Where = "  Sys_UserRoles.R_UserID = " + R_UserID.ToString();
            int RecordCount = 0;
            return DALHelper.CMNHelper.Sys_UserRolesList(qp, false, out RecordCount);
        }

        /// <summary>
        /// 根据角色ID,返回 Sys_UserRolesTable实体类 集合
        /// </summary>
        /// <param name="roleid">角色ID</param>
        /// <returns>返回Sys_UserRolesTable实体类 为0则无记录</returns>
        public  List<Sys_UserRolesEntity> Sys_UserRolesList(int roleid)
        {
            Sys_UserRolesEntity fam = new Sys_UserRolesEntity();
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
          
            qp.ReturnFields = "*";
            qp.TableName = "Sys_UserRoles";
            qp.Where = "  Sys_UserRoles.R_RoleID = " + roleid.ToString();
            int RecordCount = 0;
            return DALHelper.CMNHelper.Sys_UserRolesList(qp, false, out RecordCount);
        }
        

        /// <summary>
        /// 批量删除((用户角色表))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_UserRolesDelList(string idList)
        {
            string strDel = string.Concat("delete from  Sys_UserRoles where R_RoleID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }


        /// <summary>
        /// 批量删除((用户角色表))
        /// </summary>
        /// <param name="userid">用户id</param>
        /// <returns>删除的总个数</returns>
        public  int Sys_UserRolesDelUserId(int userId)
        {
            string strDel = string.Concat("delete from  Sys_UserRoles where R_userID =", userId.ToString());
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
 
 

    }
}
